<template>
<h1>员工列表综合练习</h1>
  <el-form>
    <el-form-item label="姓名">
      <el-input v-model="emp.name" placeholder="请输入员工姓名"/>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="emp.salary" placeholder="请输入员工工资"/>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="emp.job" placeholder="请输入员工岗位"/>
    </el-form-item>
    <el-form-item>
      <el-button @click="submit" type="success">提交</el-button>
    </el-form-item>
  </el-form>

  <el-table :data="emp_arr">
    <el-table-column type="index" label="编号"></el-table-column>
    <el-table-column prop="name" label="编号"></el-table-column>
    <el-table-column prop="salary" label="编号"></el-table-column>
    <el-table-column prop="job" label="编号"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import {ref} from "vue";


const emp = ref({
  name:'',
  salary:'',
  job:''
})
const emp_arr = ref([])

const submit = ()=>{

  //Boolean   null、undefined、NaN、''、0这五个特殊值转为boolean是false

  if(!emp.value.name||!emp.value.name.trim()||
      !emp.value.salary||!emp.value.salary.trim()||
      !emp.value.job||!emp.value.job.trim()
  ){
    alert('请输入员工完整信息');
    return;
  }
  /*emp_arr.value.push(emp.value)*/
  emp_arr.value.push({
    name:emp.value.name,
    salary:emp.value.salary,
    job:emp.value.job
  })

  console.log(emp_arr.value)
  emp.value={name:'', salary:'', job:''}
}
const del = (i,row)=>{
  if(confirm('确定要删除'+row.name+'吗')){
    emp_arr.value.splice(i,1);
  }

}

</script>


<style scoped>

</style>